package com.geek.controller;
import java.math.BigDecimal;
import java.util.Date;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.geek.domain.Orders;
import com.geek.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/orders")
@RestController
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    Snowflake snowflake = IdUtil.createSnowflake(1, 1);

    /**
     *  耗时： 太慢
     */
    @PostMapping("/batchInsert")
    public void batchInsert() {
        List<Orders> ordersList = new ArrayList<>(1000000);
        for (int i = 0; i < 1000000; i++) {
            Orders orders = new Orders();
            orders.setOrderId(snowflake.nextId());
            orders.setNotes("1");
            ordersList.add(orders);
        }
        long start = System.currentTimeMillis();
        ordersService.batchInsert(ordersList);
        long end = System.currentTimeMillis();
        System.out.println("耗时：" + (end - start) / 1000);
    }
}
